﻿using System.Collections.Generic;
using System.Threading.Tasks;
using WeiboWPSdk.Json;
using WeiboWPSdk.ResponseEntity;

namespace WeiboWPSdk.Api {
    public class AccountApi:ApiBase {
        public AccountApi(ClientHttpHelper httpHelper)
            : base(httpHelper) {
        }

        #region 读取接口
        /// <summary>
        /// 获取当前登录用户的隐私设置
        /// http://open.weibo.com/wiki/2/account/get_privacy
        /// </summary>
        /// <returns></returns>
        public async Task<Privacy> GetPrivacySettingsAsync() {
            var json = await HttpHelper.GetBasicCommandAsync("account/get_privacy");
            return JsonConvert.DeserializeObject<Privacy>(json);
        }
        /// <summary>
        /// 获取所有的学校列表
        /// http://open.weibo.com/wiki/2/account/profile/school_list
        /// 参数keyword与capital二者必选其一，且只能选其一
        /// 按首字母capital查询时，必须提供province参数
        /// </summary>
        /// <param name="province">省份范围，省份ID。</param>
        /// <param name="city">城市范围，城市ID。</param>
        /// <param name="area">区域范围，区ID。</param>
        /// <param name="type">学校类型，1：大学、2：高中、3：中专技校、4：初中、5：小学，默认为1。</param>
        /// <param name="capital">学校首字母，默认为A。</param>
        /// <param name="keyword">学校名称关键字。</param>
        /// <param name="count">返回的记录条数，默认为10。</param>
        /// <returns></returns>
        public async Task<IEnumerable<School>> GetSchoolListAsync(int province = 0, int city = 0, int area = 0, int type = 1, string capital = "A", string keyword = null, int count = 10) {
            var json = await HttpHelper.GetBasicCommandAsync("account/profile/school_list", new WeiboParameter("province", province), new WeiboParameter("city", city), new WeiboParameter("area", area),
                new WeiboParameter("type", type), new WeiboParameter("capital", capital), new WeiboParameter("keyword", keyword), new WeiboParameter("count", count));
            return JsonConvert.DeserializeObject<IEnumerable<School>>(json);
        }
        /// <summary>
        /// 获取当前登录用户的API访问频率限制情况
        /// http://open.weibo.com/wiki/2/account/rate_limit_status
        /// </summary>
        /// <returns></returns>
        public async Task<RateLimitStatus> GetRateLimitStatusAsync() {
            var json = await HttpHelper.GetBasicCommandAsync("account/rate_limit_status");
            return JsonConvert.DeserializeObject<RateLimitStatus>(json);
        }
        /// <summary>
        /// OAuth授权之后，获取授权用户的UID
        /// http://open.weibo.com/wiki/2/account/get_uid
        /// 该API已弃用，若要获取登陆用户UID，请使用OAuth2类的LoginUId
        /// </summary>
        public void GetUIdAsync() { }
        #endregion
        #region 写入接口
        /// <summary>
        /// 退出登录
        /// http://open.weibo.com/wiki/2/account/end_session
        /// </summary>
        /// <returns></returns>
        public async Task<User> EndSessionAsync() {
            var json = await HttpHelper.GetBasicCommandAsync("account/end_session");
            return JsonConvert.DeserializeObject<User>(json);
        }
        #endregion
    }
}
